﻿Imports System.Data.OleDb

Public Class NhanVienDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select * from NHANVIEN where TinhTrang=True"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As NhanVienDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into NHANVIEN (HoTen, CMND, GioiTinh, NgaySinh, DiaChi, DienThoai, MaBC, MaCV, TinhTrang) " _
                            & "values (@HoTen, @CMND, @GioiTinh, @NgaySinh, @DiaChi, @DienThoai, @MaBC, @MaCV, @TinhTrang)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8, para9 As OleDbParameter
        para1 = New OleDbParameter("@HoTen", tmp.HoTen)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@GioiTinh", tmp.GioiTinh)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@DiaChi", tmp.DiaChi)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@DienThoai", tmp.DienThoai)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@MaBC", tmp.MaBC)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@MaCV", tmp.MaCV)
        cmd.Parameters.Add(para8)
        para9 = New OleDbParameter("@TinhTrang", tmp.TinhTrang)
        cmd.Parameters.Add(para9)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As NhanVienDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update NHANVIEN set HoTen=@HoTen, CMND=@CMND, GioiTinh=@GioiTinh, NgaySinh=@NgaySinh, DiaChi=@DiaChi, DienThoai=@DienThoai, MaBC=@MaBC, MaCV=@MaCV, TinhTrang=@TinhTrang where MaNV=@MaNV"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7, para8, para9, para10 As OleDbParameter
        para1 = New OleDbParameter("@HoTen", tmp.HoTen)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@CMND", tmp.CMND)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@GioiTinh", tmp.GioiTinh)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@NgaySinh", tmp.NgaySinh)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@DiaChi", tmp.DiaChi)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@DienThoai", tmp.DienThoai)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@MaBC", tmp.MaBC)
        cmd.Parameters.Add(para7)
        para8 = New OleDbParameter("@MaCV", tmp.MaCV)
        cmd.Parameters.Add(para8)
        para9 = New OleDbParameter("@TinhTrang", tmp.TinhTrang)
        cmd.Parameters.Add(para9)
        para10 = New OleDbParameter("@MaNV", tmp.MaNV)
        cmd.Parameters.Add(para10)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As NhanVienDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from CHUCVU where MaNV=@MaNV"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaNV", tmp.MaNV)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class